package site.shihuan.helpdesk.auth.controller;

import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;
import site.shihuan.helpdesk.auth.service.AliYunOss;
import site.shihuan.helpdesk.common.model.RestResult;
import site.shihuan.helpdesk.common.model.RestResultUtils;
import site.shihuan.helpdesk.security.context.UserContext;
import site.shihuan.helpdesk.security.context.UserContextHolder;

import javax.servlet.http.HttpServletRequest;
import java.io.IOException;

/**
 * 附件API
 *
 * @author 周世焕
 * @Date 2021/5/10 21:30
 */
@RestController
@RequestMapping("/v1/auth/file")
@Slf4j
public class FileController {

    @Autowired
    private AliYunOss aliYunOss;

    @PostMapping
    public RestResult uploadFile(@RequestParam("upload_file") MultipartFile uploadFile) throws IOException {
        UserContext.getUser();
        String url = aliYunOss.upload(uploadFile);
        return RestResultUtils.success(url);
    }
}
